package me.yushuai.wukong.base.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import me.yushuai.wukong.base.api.dto.LocationTurnover;
import me.yushuai.wukong.base.api.dto.LocationUsage;
import me.yushuai.wukong.common.domain.AbstractAudit;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;

/**
 * 库位
 *
 * @author zhoushuai@189.cn
 * @TableName BAS_LOCATION
 */
@Getter
@Setter
@ToString
@Entity
@Table(name = "BAS_LOCATION", uniqueConstraints = {@UniqueConstraint(columnNames = {"BIZ_ID"})})
public class Location extends AbstractAudit implements Serializable {

    public static final String ID = "id";

    public static final String BIZ_ID = "biz_id";

    public static final String LOGICAL_SEQUENCE = "logicalSequence";

    /**
     * 库位ID
     */
    @Id
    @Column(name = "ID")
    private Long id;

    /**
     * 库位编码
     */
    @Column(name = "BIZ_ID", updatable = false, nullable = false)
    private String bizId;

    /**
     * 逻辑顺序
     */
    @Column(name = "LOGICAL_SEQUENCE")
    private Long logicalSequence;

    /**
     * 设施编号
     */
    @Column(name = "FACILITY_ID")
    private String facilityId;

    /**
     * 状态
     */
    @Column(name = "LOC_STATUS")
    private String status;

    /**
     * 库位使用方式
     * <ul>
     *     <li>无</li>
     *     <li>存储库位</li>
     *     <li>箱拣货库位</li>
     *     <li>件拣货库位</li>
     *     <li>箱/件合并拣货库位</li>
     *     <li>过渡库位</li>
     *     <li>理货站</li>
     *     <li>组装工作区</li>
     *     <li>播种库位</li>
     *     <li>快拣补货位</li>
     *     <li>补充拣货位</li>
     * </ul>
     */
    @Enumerated
    @Column(name = "LOC_USAGE")
    private LocationUsage usage;

    /**
     * 库位属性
     * <ul>
     *     <li>无</li>
     *     <li>正常</li>
     *     <li>封存</li>
     *     <li>管控</li>
     *     <li>紧入</li>
     * </ul>
     */
    @Column(name = "LOC_ATTRIBUTE")
    private LocationAttribute locationAttribute;

    /**
     * 库位类型
     * 无、货架、地面平仓、重力式货架、窄巷道货架、已拣货库位
     */
    @Column(name = "LOC_CATEGORY")
    private String category;

    /**
     * 库位处理
     * <p>
     * 无、其他、仅限与托盘、仅限于箱
     */
    @Column(name = "LOC_HANDLING")
    private String locationHandling;

    /**
     * 体积限制
     */
    @Column(name = "CUBIC_CAPACITY")
    private BigDecimal cubicCapacity;

    /**
     * 重量限制
     */
    @Column(name = "WEIGHT_CAPACITY")
    private BigDecimal weightCapacity;

    /**
     * 数量限制
     */
    @Column(name = "COUNT_CAPACITY")
    private Integer countCapacity;

    /**
     * 托盘数量限制
     */
    @Column(name = "PL_COUNT")
    private Integer palletQtyMaxLimit;

    /**
     * 上架区关联库区
     */
    @Column(name = "PUT_AWAY_ZONE_ID")
    private Long putAwayZoneId;

    /**
     * 拣货区关联库区
     */
    @Column(name = "PICK_ZONE_ID")
    private Long pickZoneId;

    /**
     * 库位组1
     */
    @Column(name = "LOC_GROUP1_ID")
    private Long locGroup1Id;

    /**
     * 库位组
     */
    @Column(name = "LOC_GROUP2_ID")
    private Long locGroup2Id;

    /**
     * 长度
     */
    @Column(name = "LENGTH")
    private BigDecimal length;

    /**
     * 宽度
     */
    @Column(name = "WIDTH")
    private BigDecimal width;

    /**
     * 高度
     */
    @Column(name = "HEIGHT")
    private BigDecimal height;

    /**
     * 层数
     */
    @Column(name = "LOC_LEVEL")
    private Integer locLevel;

    /**
     * 环境
     */
    @Column(name = "ENVIRONMENT")
    private String environment;

    /**
     * 周转需求， 无、快速周转、中速周转、慢速周转
     */
    @Enumerated
    @Column(name = "DEMAND")
    private LocationTurnover demand;

    /**
     * 是否允许混放产品
     */
    @ColumnDefault("'N'")
    @Column(name = "MIX_FLAG")
    @Type(type = "yes_no")
    private Boolean mixFlag;

    /**
     * 是否允许混放批次
     */
    @ColumnDefault("'N'")
    @Column(name = "MIX_LOT_FLAG")
    @Type(type = "yes_no")
    private Boolean mixLotFlag;

    /**
     * 是否忽略ID
     */
    @Column(name = "LOSE_ID_FLAG")
    @Type(type = "yes_no")
    private Boolean loseIdFlag;

    /**
     * 拣货顺序
     */
    @Column(name = "PICK_LOGICAL_SEQUENCE")
    private String pickLogicalSequence;

    /**
     * X坐标
     */
    @Column(name = "X_COORD")
    private Integer xCoord;

    /**
     * Y坐标
     */
    @Column(name = "Y_COORD")
    private Integer yCoord;

    /**
     * Z坐标
     */
    @Column(name = "Z_COORD")
    private Integer zCoord;

    /**
     * 箱数最大限制
     */
    @Column(name = "CS_COUNT")
    private Integer boxQtyMaxLimit;

    /**
     * X像素
     */
    @Column(name = "X_DISTANCE")
    private Integer xDistance;

    /**
     * Y像素
     */
    @Column(name = "Y_DISTANCE")
    private Integer yDistance;

    /**
     * 校验码条码
     */
    @Column(name = "VALIDATION_CODE")
    private String barcode;

    /**
     * 工作区域
     */
    @Column(name = "WORKING_AREA_ID")
    private Long workingAreaId;

    /**
     * WCS端口号1
     */
    @Column(name = "WCS_ADDRESS1")
    private String wcsAddress1;

    /**
     * WCS端口号2
     */
    @Column(name = "WCS_ADDRESS2")
    private String wcsAddress2;

    /**
     * 端口号
     */
    @Column(name = "TERMINAL_NO")
    private String terminalNo;

    /**
     * SKU数的最大限制
     * 允许存放的SKU的最大数量
     */
    @Column(name = "SKU_COUNT")
    private Integer skuQtyMaxCount;

    /**
     * ASRS 巷道号
     */
    @Column(name = "AISLE_NO")
    private String aisleNo;

    /**
     * 冻结状态
     */
    @Type(type = "yes_no")
    @ColumnDefault("'Y'")
    @Column(name = "frozen")
    private Boolean frozen;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        Location location = (Location) o;
        return Objects.equals(getId(), location.getId())
                && Objects.equals(getBizId(), location.getBizId())
                && Objects.equals(getLogicalSequence(), location.getLogicalSequence())
                && Objects.equals(getFacilityId(), location.getFacilityId())
                && Objects.equals(getStatus(), location.getStatus())
                && getUsage() == location.getUsage()
                && getLocationAttribute() == location.getLocationAttribute()
                && Objects.equals(getCategory(), location.getCategory())
                && Objects.equals(getLocationHandling(), location.getLocationHandling())
                && Objects.equals(getCubicCapacity(), location.getCubicCapacity())
                && Objects.equals(getWeightCapacity(), location.getWeightCapacity())
                && Objects.equals(getCountCapacity(), location.getCountCapacity())
                && Objects.equals(getPalletQtyMaxLimit(), location.getPalletQtyMaxLimit())
                && Objects.equals(getPutAwayZoneId(), location.getPutAwayZoneId())
                && Objects.equals(getPickZoneId(), location.getPickZoneId())
                && Objects.equals(getLocGroup1Id(), location.getLocGroup1Id())
                && Objects.equals(getLocGroup2Id(), location.getLocGroup2Id())
                && Objects.equals(getLength(), location.getLength())
                && Objects.equals(getWidth(), location.getWidth())
                && Objects.equals(getHeight(), location.getHeight())
                && Objects.equals(getLocLevel(), location.getLocLevel())
                && Objects.equals(getEnvironment(), location.getEnvironment())
                && getDemand() == location.getDemand()
                && Objects.equals(getMixFlag(), location.getMixFlag())
                && Objects.equals(getMixLotFlag(), location.getMixLotFlag())
                && Objects.equals(getLoseIdFlag(), location.getLoseIdFlag())
                && Objects.equals(getPickLogicalSequence(), location.getPickLogicalSequence())
                && Objects.equals(xCoord, location.xCoord)
                && Objects.equals(yCoord, location.yCoord)
                && Objects.equals(zCoord, location.zCoord)
                && Objects.equals(getBoxQtyMaxLimit(), location.getBoxQtyMaxLimit())
                && Objects.equals(xDistance, location.xDistance)
                && Objects.equals(yDistance, location.yDistance)
                && Objects.equals(getBarcode(), location.getBarcode())
                && Objects.equals(getWorkingAreaId(), location.getWorkingAreaId())
                && Objects.equals(getWcsAddress1(), location.getWcsAddress1())
                && Objects.equals(getWcsAddress2(), location.getWcsAddress2())
                && Objects.equals(getTerminalNo(), location.getTerminalNo())
                && Objects.equals(getSkuQtyMaxCount(), location.getSkuQtyMaxCount())
                && Objects.equals(getAisleNo(), location.getAisleNo())
                && Objects.equals(getFrozen(), location.getFrozen());
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), getId(), getBizId(), getLogicalSequence(), getFacilityId(), getStatus()
                , getUsage(), getLocationAttribute(), getCategory(), getLocationHandling(), getCubicCapacity()
                , getWeightCapacity(), getCountCapacity(), getPalletQtyMaxLimit(), getPutAwayZoneId(), getPickZoneId()
                , getLocGroup1Id(), getLocGroup2Id(), getLength(), getWidth(), getHeight(), getLocLevel()
                , getEnvironment(), getDemand(), getMixFlag(), getMixLotFlag(), getLoseIdFlag()
                , getPickLogicalSequence(), xCoord, yCoord, zCoord, getBoxQtyMaxLimit(), xDistance, yDistance
                , getBarcode(), getWorkingAreaId(), getWcsAddress1(), getWcsAddress2(), getTerminalNo()
                , getSkuQtyMaxCount(), getAisleNo(), getFrozen());
    }
}